<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 2018/6/25
 * Time: 16:19
 */

namespace app\common\model;


use think\Model;

class GiveOrder extends Model
{
    public function getGiveOrderByUserId($id,$page,$pageSize = 10){
        if(!$id && !is_numeric($id)){
            exception("传递的ID不合法");
        }

        $offset = ($page - 1) * $pageSize;

        $where = array(
            'go.status' => 1,
            'go.user_id' => $id
        );

        return $this->alias("go")->where($where)->limit($offset,$pageSize)->select();
    }

    //根据赠送订单表中的课程ID获取课程信息
    public function getGiveOrderCourseById($id){
        if(!$id && !is_numeric($id)){
            exception("传递的ID不合法");
        }

        $where = array(
            'go.status' => 1,
            'go.id' => $id
        );

        return $this->alias("go")->where($where)->join("xm_courses c","go.course_id=c.id")->join("xm_users u","go.user_id=u.id")->join("xm_author a","c.author_id=a.id")->field("u.name,c.id as course_id,c.title,c.img_url,c.price,a.name as username,go.id")->find();

    }
}